module.exports = {
    apps: [
        // Vue TurboRepo Stack 后端API服务器 (Hono + tRPC)
        {
            name: 'vue-turbo-stack-api',
            script: 'bun',
            args: 'apps/api/dist/index.js',
            cwd: '/root/ke-hu-bai-fang-system',
            instances: 1,
            exec_mode: 'fork',
            env: {
                NODE_ENV: 'production',
                PORT: 3017,
                API_URL: 'http://47.92.153.176:3017'
            },
            env_production: {
                NODE_ENV: 'production',
                PORT: 3017,
                API_URL: 'http://47.92.153.176:3017'
            },
            // 日志配置
            log_file: './logs/api-combined.log',
            out_file: './logs/api-out.log',
            error_file: './logs/api-error.log',
            log_date_format: 'YYYY-MM-DD HH:mm:ss Z',

            // 自动重启配置
            watch: false,
            ignore_watch: ['node_modules', 'logs', 'dist'],
            max_memory_restart: '500M',

            // 进程管理
            min_uptime: '10s',
            max_restarts: 10,
            autorestart: true,
            restart_delay: 4000,

            // 其他配置
            merge_logs: true,
            time: true,

            // 健康检查
            health_check_url: 'http://47.92.153.176:3017/health',
            health_check_grace_period: 3000
        },

        // Vue TurboRepo Stack Web 前端服务 (Vue 3 + Vite)
        {
            name: 'vue-turbo-stack-web',
            script: 'bunx',
            args: 'serve -s apps/web/dist -l 5173',
            cwd: '/root/ke-hu-bai-fang-system',
            instances: 1,
            exec_mode: 'fork',
            env: {
                NODE_ENV: 'production',
                PORT: 5173,
                API_URL: 'http://47.92.153.176:3017'
            },
            // 日志配置
            log_file: './logs/web-combined.log',
            out_file: './logs/web-out.log',
            error_file: './logs/web-error.log',
            log_date_format: 'YYYY-MM-DD HH:mm:ss Z',

            // 自动重启配置
            watch: false,
            max_memory_restart: '300M',

            // 进程管理
            min_uptime: '10s',
            max_restarts: 10,
            autorestart: true,
            restart_delay: 4000,

            // 其他配置
            merge_logs: true,
            time: true
        },

        // Vue TurboRepo Stack Web Mobile 前端服务 (Vue 3 + Vite + ElementPlus)
        {
            name: 'vue-turbo-stack-web-mobile',
            script: 'bunx',
            args: 'serve -s apps/web-mobile/dist -l 5174',
            cwd: '/root/ke-hu-bai-fang-system',
            instances: 1,
            exec_mode: 'fork',
            env: {
                NODE_ENV: 'production',
                PORT: 5174,
                API_URL: 'http://47.92.153.176:3017'
            },
            // 日志配置
            log_file: './logs/web-mobile-combined.log',
            out_file: './logs/web-mobile-out.log',
            error_file: './logs/web-mobile-error.log',
            log_date_format: 'YYYY-MM-DD HH:mm:ss Z',

            // 自动重启配置
            watch: false,
            max_memory_restart: '300M',

            // 进程管理
            min_uptime: '10s',
            max_restarts: 10,
            autorestart: true,
            restart_delay: 4000,

            // 其他配置
            merge_logs: true,
            time: true
        }
    ]
};